//
//  ForgetPwdVC.swift
//  whale
//
//  Created by topnet on 2022/7/27.
//

import UIKit

class ForgetPwdVC: ICBaseVC {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func _initData() {
        accountLbl.text = "当前账号"
    }
    
    override func _initUI() {
        super._initUI()
        navBar.titleV.text = "忘记密码"
        
        view.da.addSubviews(sub: [
            accountLbl,
            codeTf,
            nextBtn
        ])
    }
    
    override func _initFrame() {
        super._initFrame()
        
        accountLbl.left_right(view, x: 10.adapter).height(30.adapter).top(navBar.frame.maxY + 30.adapter)
        codeTf.left_right_offsetTop(accountLbl, x: 10.adapter).height(50.adapter)
        codeTf.da.line()
        nextBtn.left_right_height_offsetTop(codeTf, x: 20.adapter)
        nextBtn.setBackgroundImage(UIImage.createImg(color: ._blue, rect: nextBtn.bounds), for: .normal)
        nextBtn.setBackgroundImage(UIImage.createImg(color: .bg, rect: nextBtn.bounds), for: .disabled)
    }
    
    private func actionNext() {
        
    }
    
    private func textChange(_ str: String) {
        if (codeTf.text?.count ?? 0) > 0 {
            nextBtn.isEnabled = true
        }else {
            nextBtn.isEnabled = false
        }
    }
    
    private lazy var accountLbl: UILabel = {
        let lbl = UILabel()
        lbl.textColor = .title
        lbl.font = .font(17)
        return lbl
    }()
    
    lazy var codeTf: CodeTextField = {
       let tf = CodeTextField()
        tf.font = .font(15)
        tf.hintText = "请输入验证码"
        tf.isRightTextClosure = { [weak self] isRight, _ in
            self?.nextBtn.isEnabled = isRight
        }
        tf.rx.text.orEmpty.changed.subscribe { [weak self] str in
            self?.textChange(str)
        }.disposed(by: disposeBag)
        return tf
    }()
    
    private lazy var nextBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setTitleColor(.white, for: .normal)
        btn.setTitleColor(.content, for: .disabled)
        btn.setTitle("确定", for: .normal)
        btn.layer.cornerRadius = 25.adapter
        btn.layer.masksToBounds = true
        btn.isEnabled = false
        btn.rx.tap.throttle(.milliseconds(800), scheduler: MainScheduler.instance).subscribe { [weak self] _ in
            self?.actionNext()
        }.disposed(by: disposeBag)
        return btn
    }()

    private lazy var disposeBag = DisposeBag()
}
